home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / update / tpasc302.cpt / TCL Update / New ArtClass Files / CPaintTask.p < prev    next >
Encoding:
Text File  |  1990-05-11  |  2.8 KB  |  123 lines

  1. {****************************************************}
  2. {         CPaintTask.p}
  3. {}
  4. {        The PaintTask Class}
  5. {}
  6. {        SUPERCLASS = CMouseTask}
  7. {}
  8. {        Copyright ⌐ 1989, Symantec Corporation.  All rights reserved.            }
  9. {}
  10. {****************************************************}
  11.  
  12. unit CPaintTask;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, MoreTCL, ArtClassIntf;
  18.  
  19. implementation
  20.  
  21.  
  22.  
  23. {*** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ***}
  24.  
  25.  
  26.  
  27. {****************************************************}
  28. { IPaintTask}
  29. {}
  30. {        Initialize a PaintTask object}
  31. {}
  32. {****************************************************}
  33.  
  34.     procedure CPaintTask.IPaintTask (aNameIndex: integer; aPaintPane: CPaintPane; aPainting: CBitMap);
  35.     begin
  36.         inherited IMouseTask(aNameIndex);
  37.  
  38.         itsPaintPane := aPaintPane;
  39.         itsPainting := aPainting;
  40.         itsUndoBits := nil;
  41.     end;
  42.  
  43.  
  44. {****************************************************}
  45. { Free (OVERRIDE)}
  46. {}
  47. {        Dispose of a PaintTask object}
  48. {}
  49. {****************************************************}
  50.  
  51.     procedure CPaintTask.Free;
  52.     begin
  53.         if itsUndoBits <> nil then
  54.             itsUndoBits.Free;
  55.  
  56.         inherited Free;                { Pass message on to superclass    }
  57.     end;
  58.  
  59.  
  60. {****************************************************}
  61. { Undo (OVERRIDE)}
  62. {}
  63. {        Undo an action performed by a paint task}
  64. {}
  65. {****************************************************}
  66.  
  67.     procedure CPaintTask.Undo;
  68.         var
  69.             bounds: Rect;
  70.     begin
  71.         if itsUndoBits <> nil then
  72.             begin
  73.                 itsUndoBits.GetBounds(bounds);
  74.  
  75.                 CopyBits(itsPainting.macBitMap, gScratchPad.macBitMap, bounds, bounds, srcCopy, nil);
  76.  
  77.                 CopyBits(itsUndoBits.macBitMap, itsPainting.macBitMap, bounds, bounds, srcCopy, nil);
  78.  
  79.                 CopyBits(gScratchPad.macBitMap, itsUndoBits.macBitMap, bounds, bounds, srcCopy, nil);
  80.  
  81.                 itsPaintPane.Prepare;
  82.                 itsPainting.CopyFrom(bounds, bounds, nil);
  83.             end;
  84.     end;
  85.  
  86.  
  87. {****************************************************}
  88. { SaveForUndo}
  89. {}
  90. {        Save an area of the Painting so a change can be undone}
  91. {}
  92. {****************************************************}
  93.  
  94.     procedure CPaintTask.SaveForUndo (undoRect: Rect);
  95.         var
  96.             theUndoBits: CBitMap;       { Altered by TCL Weaver 1.0 (5/9/90) }
  97.  
  98.     begin
  99.                                     { Put changed area of painting into    }
  100.                                     {   an undo bitmap                        }
  101.  
  102.         new(theUndoBits);           { Altered by TCL Weaver 1.0 (5/9/90) }
  103.         itsUndoBits := theUndoBits;
  104.         gApplication.RequestMemory(TRUE, TRUE);
  105.         itsUndoBits.IBitMap(undoRect.right - undoRect.left, undoRect.bottom - undoRect.top, FALSE);
  106.         gApplication.RequestMemory(FALSE, FALSE);
  107.  
  108.         if itsUndoBits.macBitMap.baseAddr = nil then
  109.             begin
  110.                 itsUndoBits.Free;
  111.                 itsUndoBits := nil;
  112.  
  113.             end
  114.         else
  115.             begin
  116.                 itsUndoBits.SetBoundsOrigin(undoRect.left, undoRect.top);
  117.  
  118.                 CopyBits(itsPainting.macBitMap, itsUndoBits.macBitMap, undoRect, undoRect, srcCopy, nil);
  119.             end;
  120.     end;
  121.  
  122.  
  123. end.